<template>
  <div class="container">
    <Header></Header>
    <div class="block">
      <el-timeline class="main-container">
        <el-timeline-item :timestamp="blog.created" placement="top" v-for="blog in blogs">
          <el-card>
            <h4>
              <router-link :to="{path:`/blog/${blog.id}`}">
                <span style="font-size:18px" class="font-style" v-html="blog.title"></span>
              </router-link>
            </h4>
            <p v-html="blog.description"></p>
          </el-card>
        </el-timeline-item>

      </el-timeline>

      <el-pagination class="mpage"
                     background
                     layout="prev,pager,next"
                     :current-page="currentPage"
                     :page-size="pageSize"
                     hide-on-single-page
                     :total="total"
                     @current-change="search">
      </el-pagination>

    </div>

  </div>
</template>

<script>
import Header from "../components/Header";

export default {
  components: {
    Header
  },
  name: "SearchBlogs",
  data() {
    return {
      blogs: {},
      total: 0,
      currentPage: 1,
      pageSize: 5,
      keyword: ""
    }
  },
  methods: {
    search(currentPage) {
      console.log("page：" + currentPage)
      this.$axios.get("/search?keyword=" + this.keyword + "&page=" + currentPage).then(res => {
        this.blogs = res.data.data.blogs
        this.currentPage = res.data.data.page
        this.total = res.data.data.total
      })
    }
  },
  created() {
    this.keyword = this.$route.params.keyword;
    this.search(1)
  }
}
</script>

<style scoped>
.main-container {
  width: 80%;
  margin: 0 auto;
}

.font-style {
  color: darkgray;
}

a {
  text-decoration: none;
}

.block {
  margin: 0 auto;
}

.router-link-active {
  text-decoration: none;
}

.mpage {
  margin: 0 auto;
  text-align: center;
}
</style>
